package cn.com.frame.util;

import java.util.HashMap;
import java.util.Map;

public class URLStringUtil {


    /**
     * 解析url里面的参数值 返回在map集合里面
     * @param url
     * @return
     */
    public static Map<String, String> analysis(String url) {
        Map<String, String> paramMap = new HashMap<String, String>();
        try{
            if (!"".equals(url)) {// 如果URL不是空字符串
                url = url.substring(url.indexOf('?') + 1);
                String paramaters[] = url.split("&");
                String values[];
                for (String param : paramaters) {
                    values = param.split("=");
                    paramMap.put(values[0], values[1]);
                }
            }
        }catch (Exception e){
            return paramMap;
        }

        return paramMap;
    }


    public static void main(String[] args) {
        Map<String, String> paramMap = analysis("是个负担发光时代https://detail.tmall.com/item.htm?id=544834509697&spm=a219t.7664554.1998457203.105.34ee3259DpuP1U");
        System.out.println("id =" +paramMap.get("id"));
    }
}
